package com.fzb.ftp;

import java.io.File;


public class FtpManager {

    public void putFile(FtpUser ftpUser, final File file) {
        FtpLoginSuccCallBack callBack = new FtpLoginSuccCallBack() {
            @Override
            public void callBack(FtpSession ftpSession) {
                new FtpRequestImpl(ftpSession).sendCmd("put " + file.toString());
                while (FtpRequestImpl.getLock()) {

                }
            }

            @Override
            public void callBackSucc(FtpSession ftpSession) {
                ftpSession.close();
            }
        };
        FtpNIOClient ftpNIOClient = new FtpNIOClient(callBack, ftpUser);
        ftpNIOClient.connectServer();
    }

    public void sendCmd(FtpUser ftpUser, final String... cmds) {
        FtpLoginSuccCallBack callBack = new FtpLoginSuccCallBack() {
            @Override
            public void callBack(FtpSession ftpSession) {
                for (String cmd : cmds) {
                    System.out.println("send cmd --> " + cmd);
                    new FtpRequestImpl(ftpSession).sendCmd(cmd);
                }
                while (FtpRequestImpl.getLock()) {

                }
            }

            @Override
            public void callBackSucc(FtpSession ftpSession) {
                ftpSession.close();
                System.exit(0);
            }
        };
        FtpNIOClient ftpNIOClient = new FtpNIOClient(callBack, ftpUser);
        ftpNIOClient.connectServer();
    }
}
